function walk(ast, { enter, leave }) {
  visit(ast, enter, leave)
}

function visit(node, enter, leave) {
  if (!node) return
  if (enter) {
    enter(node)
  }
  let childKeys = Object.keys(node).filter(key => typeof node[key] == 'object')
  childKeys.forEach(childKey => {
    visit(node[childKey], enter, leave)
  })
  if (leave) {
    leave(node)
  }
}

module.exports = walk
